package mark.tom.gear.view.activity

import android.app.Activity
import android.os.Bundle
import android.os.Process
import mark.tom.gear.R
import mark.tom.gear.utils.MultiDexUtil

/**
 * @Description: 预加载Activity
 * @Author: ttmk110@163.com
 * @Package: mark.tom.gear.base.activity
 * @Date: 2021/1/15
 * @Copyright: 版权归 Mark 所有
 * <ModifyLog>
 * @ModifyContent:
 * @Author:
 * @Date:
 * </ModifyLog>
 */
class PreLoadDexActivity : Activity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_load_multidex)
        // 读取子线程的名
        var threadName = resources.getString(R.string.str_multidex_process)
        threadName = threadName.substring(1, threadName.length)
        // 开启线程
        val thread: Thread = object : Thread() {
            override fun run() {
                // 加载MultiDex
                installMultiDex()
            }
        }
        thread.name = threadName
        thread.start()
    }

    private fun installMultiDex() {
        MultiDexUtil.install(this)
        afterInstall()
    }

    private fun afterInstall() {
        // 删除啊临时文件
        MultiDexUtil.deleteTmpFile(this)
        // 关闭当前Activity
        finish()
        // 关闭当前线程
        Process.killProcess(Process.myPid())
    }

}